package zisu.netty.practice.netty.inBoundAndOutBound;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2020/7/29 10:36
 */
public class MyServerHandler extends SimpleChannelInboundHandler<Long> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {
        System.out.println("调用server-MyServerHandler-channelRead0 从客户端"+ctx.channel().remoteAddress()+" 读取到long "+msg);
        //给客户端发送一个long，，注意这里发送的是Long类型到client 那么就需要一个LongToByte 的Encoder
        ctx.writeAndFlush(98765L);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        //就把上下文所有的连接都关闭
        ctx.close();
    }
}
